<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>积分商城-${_front_title}</title>
	<meta name="keywords" content="${_front_keywords}" />
    <meta name="description" content="${_front_description}" />
    <link rel="shortcut icon" href="/static/favicon.ico"/>
    <link rel="stylesheet" href="/static/front/fonts/iconfont.css">
    <link rel="stylesheet" href="/static/front/css/base_new.css">
    <link rel="stylesheet" href="/static/front/css/library.css">
    <link rel="stylesheet" href="/static/front/css/style.css">
    <link rel="stylesheet" href="${_front_css}/mall_point.css">
 	<link rel="stylesheet" href="${_front_css}/good.css">
    <script src="/static/front/js/jquery-1.11.1.min.js"></script>
    <script src="/static/front/js/jquery.countdown.js"></script>
    <script src="/static/front/js/js.js"></script>
    <script type="text/javascript">
    $(function() {
        $('.shop_sort ul li a').bind('click', function(){
        $(this).addClass('cug').siblings().removeClass('cug');
        });
    });
    </script>
</head>

<body>
<div class="content">
  	<#include "../base/top.ftl" />
	<!-- 头部 结束 -->
    <div class="warp2_bg">
        <div class="shop_banner"></div>
        <div class="warp2">
            <div class="shop_titel"><span>共 ${pageInfo.pageList?size}件商品</span>积分商城</div>
            <div class="shop_sort">
                <ul id="type">
                    <li> 所有类别:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:" class="cug" typeId=-1>全部</a>
                        <#list typeList as type>
                        	<span>|</span>
                        	<a href="javascript:" typeId="${type.id}">${type.name }</a>	
                        </#list>
                    </li>
                </ul>
                <ul id="source">
                    <li> 积分范围:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:" class="cug" data = -1>全部</a>
                        <span>|</span>
                        <a href="javascript:" data = 1> 1000以下</a>
                        <span>|</span>
                        <a href="javascript:" data = 2>1000-5000</a>
                        <span>|</span>
                        <a href="javascript:" data = 3> 5000-10000</a>
                        <span>|</span>
                        <a href="javascript:" data = 4>10000-50000</a>
                        <span>|</span>
                        <a href="javascript:" data = 5>50000-100000</a>
                        <span>|</span>
                        <a href="javascript:" data = 6>100000以上</a>
                    </li>
                  </ul>
                  <ul>
                    <li class="li_last"> 商品名称:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="text" id="name" placeholder="商品名">
                        <button class="shop_search_but">搜索</button>
                    </li>
                </ul>
            </div>
            <div class="clearfix"></div>
            <div class="wrap00">
                <div class="shell">
                    <div id="div1" class="fl">
	                    <#if (goodBuy?size>0)>
		                    <#list goodBuy as item>
			                    <div class="fl lm">
				                     <span class="fl title">
				                     	<#if (item.username?exists) && (item.buyTime?exists) && (item.goodName?exists)>
				                     		<a href="javascript:" target="_blank">
				                     		${item.username[0..3]}...于${item.buyTime?string("yyyy-MM-dd hh-mm")}兑换了${item.goodName}
				                     	</#if>
				                     </span>
			                    </div>
		                    </#list>
	                    </#if> 
                    </div>
                </div>
            </div>
            <div class="shop_list">
                	排列方式:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <strong class="current">
                    <a href="javascript:" data=-1>默认</a>
                </strong>
                <i>|</i>
                <strong>
                    <a href="javascript:" data=1>最新</a>
                </strong>
                <i>|</i>
                <strong>
                    <a href="javascript:" data=2>热门</a>
                </strong>
                <i>|</i>
                <strong>
                    <a href="javascript:" data=3>积分</a>
                </strong>
            </div>
            <div class="shop_pro">
                <ul class="pro">
	                <#if (pageInfo.pageList?size>0)>
	                	<#list pageInfo.pageList as model>
	                		<li>
	                			<h1>
	                				<a href="javascript:;" target="_blank">
	                					<#if model.path?exists>
	                						<img src="${model.path}" border="0">
	                					</#if>
	                           		</a>
	                			</h1>
		                		<#if model.name?exists>
		                			 <h2><a href="javascript:;">${model.name}</a></h2>
		                		</#if>
		                		<#if model.amount?exists>
		                			<h2>所需积分：<span>${model.amount}</span></h2>
		                		</#if>
		                		<#if model.buyCount?exists>
		                			<h2>购买人数：${model.buyCount}人</h2>
		                		</#if>
		                        <h3>
		                        	<#if model.sum?exists && model.sum != 0>
		                        		<a onclick="showDetail(${model.id})" id="buy">立即兑换</a>
		                        	<#else>
		                        		<a href="javascript:;" style="background:#ccc;">暂无商品</a>	
		                        	</#if>
		                        	
		                        </h3>
	                        </li>
	                	</#list>
	                </#if>                  
                </ul>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
    
    <!--<div id="msgDiv" style="margin-top: -75px;"	>
	<div id="msgShut" align="right">
		<br> <a href="#" style="color: #F85959" class="close">×</a>
	</div>
	<div id="msgDetail" class="content">
		<div class="title">选择收货地址</div>
		<input id="goodId" style="display:none;" value=""/>
		<#if (cnee?exists) & (cnee?size>0)>
			<#list cnee as model>
			<input id="Fruit" style="float:left; margin-top:15px;" name="Fruit" type="radio" value="<#if model.id?exists>${model.id}</#if>"/>
				<div id="cnee" style="border:1px solid #ccc;margin-bottom: 10px;width:500px;margin-left: 35px;">
					<#if model.name?exists><span style="width:150px;text-align:left;">收货人姓名：${model.name}</span></#if>
					<#if model.phone?exists><span style="width:200px;text-align:left;">联系方式：${model.phone}</span></#if></br>
					<#if model.address?exists><span style="width:400px;text-align:left;">收货地址：${model.address}</span></#if>
				</div>
			</#list>
		</#if>
		<div style="text-align: center;">
		<input type="button" value="确定" class="determine" onclick="buy()"/>
		<input type="button" value="新增联系人" class="determine" onclick="addAddress()"/>
		</div>
	</div>
</div>
<div id="bgDiv"></div> -->
    <div id="footer">
        <div class="content">
            <#include "../base/foot.ftl" />        
        </div>
    </div>
</div>
<div class="jump_bg" id="borrowDetail" style="display: none;">
		<div class="jump_box" style="overflow-y:scroll;">
			<!--<div class="jump_close"></div>-->
			 <em class="iconfont close jump_close">&#xe621;</em>
			<div class="jump_prompt" id="borrow-title" style="display:inline">收货人地址</div>
			<input id="goodId" style="display:none;" value=""/>
			<div class="jump_word_gray">
				<#if (cnee?exists) & (cnee?size>0)>
					<#list cnee as model>
					<input id="Fruit" style="float:left; margin-top:25px;" name="Fruit" type="radio" value="<#if model.id?exists>${model.id}</#if>"/>
						<div id="cnee" style="border:1px solid #ccc;margin-bottom: 10px;width:350px;margin-left: 25px;">
							<#if model.name?exists><span style="width:150px;text-align:left;">收货人姓名：${model.name}</span></#if><br/>
							<#if model.phone?exists><span id="span1" style="width:200px;text-align:left;">联系人方式：${model.phone}</span></#if></br>
							<#if model.address?exists><span style="width:400px;text-align:left;">收货人地址：${model.address}</span></#if>
						</div>
					</#list>
				</#if>
				<div style="text-align: center;">
				<a href="javascript:;" class="determine" onclick="buy()" style="margin-left:100px;margin-top:30px;">确定</a>
				<a href="javascript:;" class="determine" onclick="addAddress()" style="margin-left:200px;margin-top:-35px;">新增</a>
				<!--<input type="button" style=""value="确定" class="determine" onclick="buy()"/>
				<input type="button" value="新增联系人" class="determine" onclick="addAddress()"/>-->
			</div>
		</div>
	</div>  

<script type="text/javascript" src="${_front_js}/layer/layer.js" ></script>
<script type="text/javascript" src="${_front_js}/layer/extend/layer.ext.js" ></script>

<script type="text/javascript">
function showDetail(id) {
	$.ajax({
			type : "POST",
			async : 'false',
			url : "/front/good/buy",
			data : {
				count : 1,
				goodId : id
			},
			success : function(result) { 
				if(result.code==1){
			    	layer.alert(result.msg, function(index){
				   		window.location.href="/login";
			   		})
			    }else if(result.code==-1){
			    	document.getElementById("goodId").value=result.entity;
			    	$("#borrowDetail").show();
			    }else{
			    	layer.alert(result.msg);
			    }
		    }
	});
}

function buy() {
		var id = $("#goodId").val();
		var cnee = $('input[name="Fruit"]:checked').val();
		if(cnee == null){
			layer.alert("请选择收货地址！");
			return;
		}
		$.ajax({
			type : "POST",
			async : 'false',
			url : "/front/good/confirm",
			data : {
				cneeId : cnee,
				goodId : id
			},
			success : function(result) { 
		        layer.alert(result.msg, function(index){
				    layer.close(index);
				    if(result.code==-1){
					 window.location.reload();
				    }
				}); 

			}
		});
	}
	
	$("#type li a").click(function(){
		var type = $(this).attr("typeId");
		$.ajax({
			type : "POST",
			async : 'false',
			url : "/good/list",
			data : {
				"typeId" : type
			},
			success : function(result) { 
				if(result.code == -1){
					$(".pro").html("");
					var entityList = result.entity.pageList;
					var html = "";
					 for(var i=0;i<entityList.length;i++){
		 				 var model = entityList[i];
		 				 var path = model.path;
		 				 var sum = model.sum ; 
						 html += '<li><h1><a><img src="../../../'+model.path+'" border="0"></a></h1>';
						 html += '<h2><a href="javascript:;">'+ model.name + '</a></h2>';
						 html += '<h2>所需积分：<span>' + model.amount+ '</span></h2>';
						 html += '<h2>购买人数：'+ model.buyCount+ '人</h2>';
						 if(sum != 0){
						 	html += '<h3><a onclick="showDetail('+model.id+')" id="buy">立即兑换</a></h3></li>';
						 }else{
							html += '<h3><a href="javascript:;" style="background:#ccc;">暂无商品</a></h3></li>';						 
						 }
					 }
					$(".pro").html(html); 
				}else{
					$(".pro").html("");
					var html = '<p style="text-align:center;">暂无商品</p>';
					$(".pro").html(html);
				}
		    }
		});
	});
	
	$("#source li a").click(function(){
		var score = $(this).attr("data");
		$.ajax({
			type : "POST",
			async : 'false',
			url : "/good/list",
			data : {
				"amount" : score
			},
			success : function(result) { 
				if(result.code == -1){
					$(".pro").html("");
					var entityList = result.entity.pageList;
					var html = "";
					 for(var i=0;i<entityList.length;i++){
		 				 var model = entityList[i];
		 				  var sum = model.sum ; 
						 html += '<li><h1><a><img src="../../../'+model.path+'" border="0"></a></h1>';
						 html += '<h2><a href="javascript:;">'+ model.name + '</a></h2>';
						 html += '<h2>所需积分：<span>' + model.amount+ '</span></h2>';
						 html += '<h2>购买人数：'+ model.buyCount+ '人</h2>';
						if(sum != 0){
						 	html += '<h3><a onclick="showDetail('+model.id+')" id="buy">立即兑换</a></h3></li>';
						 }else{
							html += '<h3><a href="javascript:;" style="background:#ccc;">暂无商品</a></h3></li>';						 
						 }
					 }
					$(".pro").html(html); 
				}else{
					$(".pro").html("");
					var html = '<p style="text-align:center;">暂无商品</p>';
					$(".pro").html(html);
				}
		    }
		});
	});
	
	$(".shop_search_but").click(function(){
		var name = $("#name").val();
		$.ajax({
			type : "POST",
			async : 'false',
			url : "/good/list",
			data : {
				"name" : name
			},
			success : function(result) { 
				if(result.code == -1){
					$(".pro").html("");
					var entityList = result.entity.pageList;
					var html = "";
					 for(var i=0;i<entityList.length;i++){
		 				 var model = entityList[i];
		 				  var sum = model.sum ; 
						 html += '<li><h1><a><img src="../../../'+model.path+'" border="0"></a></h1>';
						 html += '<h2><a href="javascript:;">'+ model.name + '</a></h2>';
						 html += '<h2>所需积分：<span>' + model.amount+ '</span></h2>';
						 html += '<h2>购买人数：'+ model.buyCount+ '人</h2>';
						if(sum != 0){
						 	html += '<h3><a onclick="showDetail('+model.id+')" id="buy">立即兑换</a></h3></li>';
						 }else{
							html += '<h3><a href="javascript:;" style="background:#ccc;">暂无商品</a></h3></li>';						 
						 }
					 }
					$(".pro").html(html); 
				}else{
					$(".pro").html("");
					var html = '<p style="text-align:center;">暂无商品</p>';
					$(".pro").html(html);
				}
		    }
		});
	})
	
	$(".shop_list strong a").click(function(){
		var sort = $(this).attr("data");
		$.ajax({
			type : "POST",
			async : 'false',
			url : "/good/list",
			data : {
				"sort" : sort
			},
			success : function(result) { 
				if(result.code == -1){
					$(".pro").html("");
					var entityList = result.entity.pageList;
					var html = "";
					 for(var i=0;i<entityList.length;i++){
		 				 var model = entityList[i];
						 html += '<li><h1><a><img src="../../../'+model.path+'" border="0"></a></h1>';
						 html += '<h2><a href="javascript:;">'+ model.name + '</a></h2>';
						 html += '<h2>所需积分：<span>' + model.amount+ '</span></h2>';
						 html += '<h2>购买人数：'+ model.buyCount+ '人</h2>';
						 html += '<h3><a onclick="showDetail('+model.id+')" id="buy">立即兑换</a></h3></li>';
					 }
					$(".pro").html(html); 
				}else{
					$(".pro").html("");
					var html = '<p style="text-align:center;">暂无商品</p>';
					$(".pro").html(html);
				}
		    }
		});
	})
	
	function addAddress(){
		window.location.href="/account/score?temp=address"
	}
	$(".jump_cancel,.jump_close").click(function(){
			$("#borrowDetail").hide();
		});
</script>
</body>

</html>
